home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / util / libs / ixemul_sdk.lha / include / sys / buf.h < prev    next >
C/C++ Source or Header  |  1998-01-15  |  9KB  |  195 lines

  1. /*    $NetBSD: buf.h,v 1.24 1996/02/18 11:55:45 fvdl Exp $    */
  2.  
  3. /*
  4.  * Copyright (c) 1982, 1986, 1989, 1993
  5.  *    The Regents of the University of California.  All rights reserved.
  6.  * (c) UNIX System Laboratories, Inc.
  7.  * All or some portions of this file are derived from material licensed
  8.  * to the University of California by American Telephone and Telegraph
  9.  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  10.  * the permission of UNIX System Laboratories, Inc.
  11.  *
  12.  * Redistribution and use in source and binary forms, with or without
  13.  * modification, are permitted provided that the following conditions
  14.  * are met:
  15.  * 1. Redistributions of source code must retain the above copyright
  16.  *    notice, this list of conditions and the following disclaimer.
  17.  * 2. Redistributions in binary form must reproduce the above copyright
  18.  *    notice, this list of conditions and the following disclaimer in the
  19.  *    documentation and/or other materials provided with the distribution.
  20.  * 3. All advertising materials mentioning features or use of this software
  21.  *    must display the following acknowledgement:
  22.  *    This product includes software developed by the University of
  23.  *    California, Berkeley and its contributors.
  24.  * 4. Neither the name of the University nor the names of its contributors
  25.  *    may be used to endorse or promote products derived from this software
  26.  *    without specific prior written permission.
  27.  *
  28.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  29.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  32.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  37.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38.  * SUCH DAMAGE.
  39.  *
  40.  *    @(#)buf.h    8.7 (Berkeley) 1/21/94
  41.  */
  42.  
  43. #ifndef _SYS_BUF_H_
  44. #define    _SYS_BUF_H_
  45. #include <sys/queue.h>
  46.  
  47. #define NOLIST ((struct buf *)0x87654321)
  48.  
  49. /*
  50.  * The buffer header describes an I/O operation in the kernel.
  51.  */
  52. struct buf {
  53.     LIST_ENTRY(buf) b_hash;        /* Hash chain. */
  54.     LIST_ENTRY(buf) b_vnbufs;    /* Buffer's associated vnode. */
  55.     TAILQ_ENTRY(buf) b_freelist;    /* Free list position if not active. */
  56.     struct    buf *b_actf, **b_actb;    /* Device driver queue when active. */
  57.     struct  proc *b_proc;        /* Associated proc; NULL if kernel. */
  58.     volatile long    b_flags;    /* B_* flags. */
  59.     int    b_error;        /* Errno value. */
  60.     long    b_bufsize;        /* Allocated buffer size. */
  61.     long    b_bcount;        /* Valid bytes in buffer. */
  62.     long    b_resid;        /* Remaining I/O. */
  63.     dev_t    b_dev;            /* Device associated with buffer. */
  64.     struct {
  65.         caddr_t    b_addr;        /* Memory, superblocks, indirect etc. */
  66.     } b_un;
  67.     void    *b_saveaddr;        /* Original b_addr for physio. */
  68.     daddr_t    b_lblkno;        /* Logical block number. */
  69.     daddr_t    b_blkno;        /* Underlying physical block number. */
  70.                     /* Function to call upon completion. */
  71.     void    (*b_iodone) __P((struct buf *));
  72.     struct    vnode *b_vp;        /* Device vnode. */
  73.     int    b_dirtyoff;        /* Offset in buffer of dirty region. */
  74.     int    b_dirtyend;        /* Offset of end of dirty region. */
  75.     struct    ucred *b_rcred;        /* Read credentials reference. */
  76.     struct    ucred *b_wcred;        /* Write credentials reference. */
  77.     int    b_validoff;        /* Offset in buffer of valid region. */
  78.     int    b_validend;        /* Offset of end of valid region. */
  79. };
  80.  
  81. /*
  82.  * For portability with historic industry practice, the cylinder number has
  83.  * to be maintained in the `b_resid' field.
  84.  */
  85. #define    b_cylinder b_resid        /* Cylinder number for disksort(). */
  86.  
  87. /* Device driver compatibility definitions. */
  88. #define    b_active b_bcount        /* Driver queue head: drive active. */
  89. #define    b_data     b_un.b_addr        /* b_un.b_addr is not changeable. */
  90. #define    b_errcnt b_resid        /* Retry count while I/O in progress. */
  91. #define    iodone     biodone        /* Old name for biodone. */
  92. #define    iowait     biowait        /* Old name for biowait. */
  93.  
  94. /*
  95.  * These flags are kept in b_flags.
  96.  */
  97. #define    B_AGE        0x00000001    /* Move to age queue when I/O done. */
  98. #define    B_NEEDCOMMIT    0x00000002    /* Needs committing to stable storage */
  99. #define    B_ASYNC        0x00000004    /* Start I/O, do not wait. */
  100. #define    B_BAD        0x00000008    /* Bad block revectoring in progress. */
  101. #define    B_BUSY        0x00000010    /* I/O in progress. */
  102. #define    B_CACHE        0x00000020    /* Bread found us in the cache. */
  103. #define    B_CALL        0x00000040    /* Call b_iodone from biodone. */
  104. #define    B_DELWRI    0x00000080    /* Delay I/O until buffer reused. */
  105. #define    B_DIRTY        0x00000100    /* Dirty page to be pushed out async. */
  106. #define    B_DONE        0x00000200    /* I/O completed. */
  107. #define    B_EINTR        0x00000400    /* I/O was interrupted */
  108. #define    B_ERROR        0x00000800    /* I/O error occurred. */
  109. #define    B_GATHERED    0x00001000    /* LFS: already in a segment. */
  110. #define    B_INVAL        0x00002000    /* Does not contain valid info. */
  111. #define    B_LOCKED    0x00004000    /* Locked in core (not reusable). */
  112. #define    B_NOCACHE    0x00008000    /* Do not cache block after use. */
  113. #define    B_PAGET        0x00010000    /* Page in/out of page table space. */
  114. #define    B_PGIN        0x00020000    /* Pagein op, so swap() can count it. */
  115. #define    B_PHYS        0x00040000    /* I/O to user memory. */
  116. #define    B_RAW        0x00080000    /* Set by physio for raw transfers. */
  117. #define    B_READ        0x00100000    /* Read buffer. */
  118. #define    B_TAPE        0x00200000    /* Magnetic tape I/O. */
  119. #define    B_UAREA        0x00400000    /* Buffer describes Uarea I/O. */
  120. #define    B_WANTED    0x00800000    /* Process wants this buffer. */
  121. #define    B_WRITE        0x00000000    /* Write buffer (pseudo flag). */
  122. #define    B_WRITEINPROG    0x01000000    /* Write in progress. */
  123. #define    B_XXX        0x02000000    /* Debugging flag. */
  124.  
  125. /*
  126.  * This structure describes a clustered I/O.  It is stored in the b_saveaddr
  127.  * field of the buffer on which I/O is done.  At I/O completion, cluster
  128.  * callback uses the structure to parcel I/O's to individual buffers, and
  129.  * then free's this structure.
  130.  */
  131. struct cluster_save {
  132.     long    bs_bcount;        /* Saved b_bcount. */
  133.     long    bs_bufsize;        /* Saved b_bufsize. */
  134.     void    *bs_saveaddr;        /* Saved b_addr. */
  135.     int    bs_nchildren;        /* Number of associated buffers. */
  136.     struct buf **bs_children;    /* List of associated buffers. */
  137. };
  138.  
  139. /*
  140.  * Zero out the buffer's data area.
  141.  */
  142. #define    clrbuf(bp) {                            \
  143.     bzero((bp)->b_data, (u_int)(bp)->b_bcount);            \
  144.     (bp)->b_resid = 0;                        \
  145. }
  146.  
  147. /* Flags to low-level allocation routines. */
  148. #define B_CLRBUF    0x01    /* Request allocated buffer be cleared. */
  149. #define B_SYNC        0x02    /* Do all allocations synchronously. */
  150.  
  151. #ifdef _KERNEL
  152. int    nbuf;            /* The number of buffer headers */
  153. struct    buf *buf;        /* The buffer headers. */
  154. char    *buffers;        /* The buffer contents. */
  155. int    bufpages;        /* Number of memory pages in the buffer pool. */
  156. struct    buf *swbuf;        /* Swap I/O buffer headers. */
  157. int    nswbuf;            /* Number of swap I/O buffer headers. */
  158. struct    buf bswlist;        /* Head of swap I/O buffer headers free list. */
  159. struct    buf *bclnlist;        /* Head of cleaned page list. */
  160.  
  161. __BEGIN_DECLS
  162. void    allocbuf __P((struct buf *, int));
  163. void    bawrite __P((struct buf *));
  164. void    bdwrite __P((struct buf *));
  165. void    biodone __P((struct buf *));
  166. int    biowait __P((struct buf *));
  167. int    bread __P((struct vnode *, daddr_t, int,
  168.            struct ucred *, struct buf **));
  169. int    breada __P((struct vnode *, daddr_t, int, daddr_t, int,
  170.             struct ucred *, struct buf **));
  171. int    breadn __P((struct vnode *, daddr_t, int, daddr_t *, int *, int,
  172.             struct ucred *, struct buf **));
  173. void    brelse __P((struct buf *));
  174. void    bremfree __P((struct buf *));
  175. void    bufinit __P((void));
  176. int    bwrite __P((struct buf *));
  177. void    cluster_callback __P((struct buf *));
  178. int    cluster_read __P((struct vnode *, u_quad_t, daddr_t, long,
  179.               struct ucred *, struct buf **));
  180. void    cluster_write __P((struct buf *, u_quad_t));
  181. struct buf *getblk __P((struct vnode *, daddr_t, int, int, int));
  182. struct buf *geteblk __P((int));
  183. struct buf *getnewbuf __P((int slpflag, int slptimeo));
  184. struct buf *incore __P((struct vnode *, daddr_t));
  185.  
  186. void    minphys __P((struct buf *bp));
  187. int    physio __P((void (*strategy)(struct buf *), struct buf *bp, dev_t dev,
  188.             int flags, void (*minphys)(struct buf *), struct uio *uio));
  189. void  brelvp __P((struct buf *));
  190. void  reassignbuf __P((struct buf *, struct vnode *));
  191. void  bgetvp __P((struct vnode *, struct buf *));
  192. __END_DECLS
  193. #endif
  194. #endif /* !_SYS_BUF_H_ */
  195.